"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/**
 * 初始化视频事件
 */
function initailizePlayerEvent(player, props) {
  player.on('play', function (event) {
    props.onPlay && props.onPlay(event);
  });
  player.on('pause', function (event) {
    props.onPause && props.onPause(event);
  });
  player.on('waiting', function (event) {
    props.onWaiting && props.onWaiting(event);
  });
  player.on('timeupdate', function (event) {
    // 当前播放的时间
    var currentTime = player.currentTime(); // 视频时长。注意：在知道视频时长之前视频必须已经开始加载，而且取决于视频的预加载行为，知道视频开始播放

    var duration = player.duration(); // detail 和小程序对齐

    props.onTimeUpdate && props.onTimeUpdate(_objectSpread(_objectSpread({}, event), {}, {
      detail: {
        currentTime: currentTime,
        duration: duration
      }
    }));
  });
  player.on('seeking', function (event) {
    player.off('timeupdate', function () {});
    player.one('seeked', function () {});
  });
  player.on('ended', function (event) {
    props.onEnded && props.onEnded(event);
  });
  player.on('error', function (event) {
    props.onError && props.onError(event);
  });
  player.on('loadedmetadata', function (event) {
    props.onLoadedMetaData && props.onLoadedMetaData(event);
  });
  player.on('fullscreenchange', function (event) {
    var isFullscreen = player.isFullscreen();
    props.onFullscreenChange && props.onFullscreenChange(_objectSpread(_objectSpread({}, event), {}, {
      detail: {
        fullScreen: isFullscreen,
        fullscreen: isFullscreen
      }
    })); // detail 和小程序对齐
  });
  player.on('progress', function (event) {
    var buffered = player.bufferedPercent();
    props.onProgress && props.onProgress(_objectSpread(_objectSpread({}, event), {}, {
      detail: {
        buffered: buffered
      }
    }));
  });
}

var _default = initailizePlayerEvent;
exports.default = _default;